package com.hongye.consult.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hongye.consult.dao.ConsultDao;
import com.hongye.consult.entity.ConsultEntity;
import com.hongye.consult.entity.HouseEntity;
import com.hongye.consult.service.ConsultService;
import com.hongye.consult.vo.DetailVo;
import com.hongye.consult.vo.FindRentingVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;


@Service
public class ConsultServiceImpl  implements ConsultService {



    @Autowired
    ConsultDao consultDao;


    @Override
    public List<ConsultEntity> findSubjectConsultation() {
        //根据时间进行区间进行去查询  当前时候的数据
        String startTime = startTime();
        String endTime = endTime();
        List<ConsultEntity> consultEntities=consultDao.findSubjectConsultation(startTime,endTime);
        return consultEntities;
    }

    @Override
    public List<HouseEntity> findConsultDetail(Integer houseId) {
        //进行通过点击获取到 房屋信息的id 进行查询房屋数据
        List<HouseEntity> detailVos=consultDao.findConsultDetail(houseId);
        return detailVos;
    }

    @Override
    public List<DetailVo> findAllConsult() {
        List<DetailVo> detailVos=consultDao.findAllConsult();
        return detailVos;
    }


    @Override
    public PageInfo<HouseEntity> findRentingList(Integer currPage, Integer pageSize, FindRentingVo findRentingVo) {

        PageHelper.startPage(currPage,pageSize);
        //进行查询数据
        List<HouseEntity> houseEntities=consultDao.findRentingList(findRentingVo);

        System.out.println(houseEntities);

        return new PageInfo<HouseEntity>(houseEntities);
    }






    //开始时间
    public String startTime() {
        //当前日期
        LocalDate now = LocalDate.now();

        LocalTime min = LocalTime.MIN;

        LocalDateTime startTime = LocalDateTime.of(now, min);

        //转转为String类型
        String format = startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));

        System.out.println(format);

        return format;
    }
    //结束时间
    private String  endTime(){
        //获取当前日期
        LocalDate now = LocalDate.now();
        //加天数(后台)
        LocalDate plusDays = now.plusDays(1);
        //每天最后那个点
        LocalTime max=LocalTime.MAX;
        //获取到时间
        LocalDateTime endTime = LocalDateTime.of(plusDays, max);
        //改为String类型
        String format = endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        System.out.println(format);

        return format;
    }
}